package com.west.common.imageloader;

import android.support.annotation.DrawableRes;
import android.widget.ImageView;

/**
 * @author hanyulang
 * @date 2018/10/12
 */
public class ImageConfigImpl extends ImageConfig {
    /**
     * 图片每个圆角的大小
     */
    private int imageRadius;

    /**
     * 高斯模糊值, 值越大模糊效果越大
     */
    private int blurValue;

    private boolean isDont;

    private boolean cancelCache;

    private ImageConfigImpl(Builder builder){
        this.url = builder.url;
        this.blurValue = builder.blurValue;
        this.imageView = builder.imageView;
        this.imageRadius = builder.imageRadius;
        this.uid = builder.uid;
        this.placeHolder = builder.placeholder;
        this.errorHolder = builder.errorHolder;
        this.isCenterCrop = builder.isCenterCrop;
        this.isCircile = builder.isCircile;
        this.isGif = builder.isGif;
        this.isDont = builder.isDont;
        this.cancelCache = builder.cancelCache;
        this.w_h = builder.w_h;
    }

    public int getImageRadius() {
        if(imageRadius <= 0){
            imageRadius = 0;
        }
        return imageRadius;
    }

    public int getBlurValue() {
        return blurValue;
    }

    public boolean isDont() {
        return isDont;
    }

    public boolean isCancelCache() {
        return cancelCache;
    }

    public static Builder builder(){
        return new Builder();
    }

    public static final class Builder{
        private String url;
        private Integer uid;
        private ImageView imageView;
        private int imageRadius;
        private int blurValue;
        private int placeholder;
        private int errorHolder;
        private boolean isCenterCrop;
        private boolean isCircile = false;
        private boolean isGif;
        private boolean isDont;
        private boolean cancelCache;
        private int[] w_h;

        public Builder url(String url){
            this.url = url;
            return this;
        }

        public Builder uid(@DrawableRes Integer uid){
            this.uid = uid;
            return this;
        }

        public Builder imageView(ImageView imageView){
            this.imageView = imageView;
            return this;
        }

        public Builder imageRadius(int imageRadius){
            this.imageRadius = imageRadius;
            return this;
        }

        public Builder placeholder(int placeholder) {
            this.placeholder = placeholder;
            return this;
        }

        public Builder errorHolder(int errorHolder){
            this.errorHolder = errorHolder;
            return this;
        }

        public Builder isCenterCrop(boolean isCenterCrop){
            this.isCenterCrop = isCenterCrop;
            return this;
        }

        public Builder isCircile(){
            this.isCircile = true;
            this.isCenterCrop = false;
            return this;
        }

        public Builder isGif(){
            this.isGif = true;
            return this;
        }

        public Builder isDont(){
            this.isDont = isDont;
            return this;
        }

        public Builder cancelCache(boolean cancelCache){
            this.cancelCache = cancelCache;
            return this;
        }

        public Builder w_h(int[] w_h){
            this.w_h = w_h;
            return this;
        }

        private Builder(){}

        public ImageConfigImpl build(){
            return new ImageConfigImpl(this);
        }
    }
}
